package edu.hawaii.duedates.tools;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

//import java.io.File;
//import java.util.ArrayList;
//import java.util.List;

//import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

//import edu.hawaii.duedates.libraries.UhLibrary;
import edu.hawaii.duedates.datastore.ResultsList;

/**
 * The unit test to assure the DueDatesMail is working properly.
 * A check is done on a bad email and smtp server values.
 * A test is done on a valid email and smtp server address.
 * 
 * @author Daniel Arakaki, John Ancheta, Mari-Lee Flestado
 * @version 1.0, November 14, 2008
 *
 */
public class TestDueDatesMail {
  
  /** Unexpected error fail string.*/
  public static final String SHOULD_NOT_FAIL = "Should not fail.";
  
//  /** An variable for the email address, instantiated to take in a command argument.*/
//  private final String emailAddress = System.getenv("EMAIL_ADDRESS");
  
//  /** An variable for the SMTP address, instantiated to take in a command argument.*/
//  private final String smtpServer = System.getenv("SMTP_SERVER");
  
  /** Instance variable for user idOne, instantiated to take in command argument. */
  /*private final String uhIdOne = System.getenv("DUEDATES_TESTUSER1_ID");*/
  
  /** Instance variable for user last nameOne, instantiated to take in command argument. */
  /*private final String lastNameOne = System.getenv("DUEDATES_TESTUSER1_LASTNAME");*/
  
  /** Instance variable for user id, instantiated to take in command argument. */
  /*private final String testUser2Id = 
                              System.getenv("DUEDATES_TESTUSER2_ID");*/

  /** Instance variable for user last name, instantiated to take in command argument. */
  /*private final String testUser2LastName = 
                              System.getenv("DUEDATES_TESTUSER2_LASTNAME");*/
  
  /**
   * Testing a failed delivery.
   * 
   * @throws Exception An exception is thrown when the mail cannot be delivered.
   */
  @Test(expected = Exception.class)
  public void testSendMail() throws Exception {
    DueDatesMail mailer = DueDatesMail.getInstance();
    // the strings should be null
    mailer.sendMail("danielma@hawaii.edu", null, "test");
  }
  
  /**
   * Testing a properly sent message.
   * 
   * @throws Exception An exception is thrown if there is a problem with parsing the ID and 
   *         last name.
   */
  @Ignore
  @Test
  public void testSendMailTwo() throws Exception {
    DueDatesMail mailer = DueDatesMail.getInstance();
    ResultsList uhInfo = new ResultsList();
    //UhLibrary uHm = new UhLibrary();
    //uhInfo = uHm.getInfo();
    try {
      assertTrue("Testing for a successfully sent msg.",
          mailer.sendMail("danielma@hawaii.edu", "mail.hawaii.edu", uhInfo.toString()));
    }
    catch (Exception e) {
      fail("Should not get here, problems with the mailer.");
      e.printStackTrace();
    }
  }
}
